﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.consts.*;
    import com.tudou.cookie.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.view.*;
    import flash.geom.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdOverlayCommand extends SimpleCommand
    {

        public function AdOverlayCommand()
        {
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_6:IAdItemInfo = null;
            var _loc_7:Rectangle = null;
            var _loc_10:Boolean = false;
            var _loc_11:Boolean = false;
            var _loc_12:Number = NaN;
            var _loc_2:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            var _loc_3:* = facade.retrieveProxy(AdOverlayProxy.NAME) as AdOverlayProxy;
            var _loc_4:* = facade.retrieveMediator(SkinMediator.NAME) as SkinMediator;
            var _loc_5:* = PageInfo.getInstance();
            var _loc_8:* = param1.getBody();
            var _loc_9:int = 0;
            switch(param1.getName())
            {
                case AdOverlayCommandSet.START:
                {
                    _loc_6 = _loc_2.getAdItemByType(AdType.OVER_LAY);
                    if (_loc_6)
                    {
                        _loc_3.adItemInfo = _loc_6;
                        _loc_3.adThrowInfo = _loc_2.throwInfo;
                        _loc_10 = false;
                        _loc_11 = false;
                        _loc_12 = 1000;
                        if (_loc_5.original && _loc_5.currRateType != RateType.ORIGINAL && !PlayerSO.getInst().getUsed(CookieConsts.NO_ORIGINAL_TIP))
                        {
                            _loc_10 = true;
                        }
                        if (_loc_5.skipHeadTail && !PlayerSO.getInst().getUsed(CookieConsts.NO_FIRST_SKIP_TIP))
                        {
                            _loc_11 = true;
                        }
                        if (_loc_10)
                        {
                            _loc_12 = _loc_12 + NewSkinConsts.ORIGINAL_TIP_TIME;
                        }
                        if (_loc_11)
                        {
                            _loc_12 = _loc_12 + NewSkinConsts.SKIP_TIP_TIME;
                        }
                        _loc_3.startAd(_loc_12);
                    }
                    break;
                }
                case AdOverlayCommandSet.CLEAR:
                {
                    _loc_9 = AdModStatus.CLEAR;
                    break;
                }
                case ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE:
                {
                    _loc_7 = PlayerConsts.FULLSCREEN_RECT;
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_3.view.goTransform(_loc_7.width, _loc_7.height, true);
                    }
                    break;
                }
                case ViewCommandSet.NORMALSCREEN_RESIZE:
                {
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_3.view.goTransform(PlayerConsts.DEFAULT_VIDEO_WIDTH, PlayerConsts.DEFAULT_VIDEO_HEIGHT, false);
                    }
                    break;
                }
                case ViewCommandSet.EXPAND_STAGE:
                {
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_3.view.isExpand = _loc_8;
                    }
                    break;
                }
                case AdOverlayCommandSet.ERROR_END:
                {
                    _loc_9 = AdModStatus.ERROR_END;
                    break;
                }
                case AdOverlayCommandSet.PREPARE_TO_SHOW:
                {
                    _loc_3.startView();
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_4.setAdOverlay(_loc_3.view.adDisplay);
                    }
                    break;
                }
                case AdOverlayCommandSet.SHOW_START:
                {
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            switch(_loc_9)
            {
                case AdModStatus.ERROR_END:
                case AdModStatus.CLEAR:
                {
                    _loc_3.clearAd();
                    _loc_4.removeAdOverlay();
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
